<!--填报课程考核实施计划-->
<template>
  <div class="assessment-container">
    <div class="search-container">
      <div class="search-container-left">
        <div class="search-container-item">
          <span>学期：</span>
          <el-select
            v-model="termid"
            style="width: 90px"
            size="mini"
            placeholder="请选择"
          >
            <el-option
              v-for="item in xqList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        <div class="search-container-item">
          <span>培养层次：</span>
          <el-select
            v-model="traininglevel"
            style="width: 88px"
            size="mini"
            placeholder="请选择"
          >
            <el-option
              v-for="item in pyccList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        <div class="search-container-item">
          <span>修习类型：</span>
          <el-select
            v-model="studytype"
            style="width: 88px"
            size="mini"
            placeholder="请选择"
          >
            <el-option
              v-for="item in xxlxList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        <div class="search-container-item">
          <span>课程名称：</span>
          <el-input
            style="width: 152px"
            size="mini"
            placeholder="请输入内容"
            v-model="coursename"
          ></el-input>
        </div>
        <div class="search-button" @click="queryPostList">
          <img src="../../../assets/assessment/icon-search.png" alt="" />
          <span>查询</span>
        </div>
      </div>
      <div class="search-container-right">
        <!--        <div class="export-button" @click="showExportReportDialog = true">-->
        <!--          <img src="../../../assets/assessment/icon-export.png" alt=""/>-->
        <!--          <span>导出分项成绩单</span>-->
        <!--        </div>-->
        <!--        <div class="export-button" @click="saveTding">-->
        <!--          <img src="../../../assets/assessment/icon-export.png" alt=""/>-->
        <!--          <span>导出总评成绩单</span>-->
        <!--        </div>-->
        <div class="import-button" @click="toMakeupScoreEntry">
          <img src="../../../assets/assessment/icon-import.png" alt="" />
          <span>录入补缓考成绩</span>
        </div>
      </div>
    </div>
    <div class="plan-entry-table-container">
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        class="table-data"
        row-class-name="row-class"
        cell-class-name="cell-class"
        header-row-class-name="header-row-class"
        header-cell-class-name="header-cell-class"
        @selection-change="handleSelectionChange"
      >
        <el-table-column width="70" align="center" type="selection">
        </el-table-column>
        <el-table-column
          prop="lrcj"
          label="录入成绩"
          width="134"
          align="center"
          class-name=""
          label-class-name=""
        >
          <template slot-scope="scope">
            <div
              class="lucj-import-button"
              @click="toManualEntry(scope.row.planid)"
            >
              <img src="../../../assets/assessment/lrcj-import.png" alt="" />
              <span>手动录入</span>
            </div>
            <div class="lucj-import-button" @click="lucjClick(scope.$index)">
              <img src="../../../assets/assessment/lrcj-import.png" alt="" />
              <span>模板导入</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="dccjd"
          label="导出成绩单"
          width="112"
          align="center"
        >
          <template slot-scope="scope">
            <div class="lucj-expot-button" @click="save(scope.$index)">
              <img src="../../../assets/assessment/icon-export.png" alt="" />
              <span>分项</span>
            </div>
            <div class="lucj-expot-button" @click="savezong(scope.$index)">
              <img src="../../../assets/assessment/icon-export.png" alt="" />
              <span>总评</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="termid" label="学期" width="79" align="center">
        </el-table-column>
        <el-table-column
          prop="teachingandresearchsection"
          label="教研室"
          width="108"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="coursenumber" width="153" align="center">
          <template slot-scope="scope" slot="header">
            <div>课程编号</div>
            <div>【课程名称】</div>
          </template>
          <template slot-scope="scope">
            <div>{{ scope.row.coursenumber }}</div>
            <div>{{ scope.row.coursename }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="grade" label="年级" width="74" align="center">
        </el-table-column>
        <el-table-column
          prop="classes"
          label="教学班"
          width="189"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="professionaldivisions"
          label="专业班次"
          width="292"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="teachingfaculty"
          label="任课教员"
          width="93"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="shouldrecord"
          label="应录"
          width="80"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="ktwork" width="105" align="center">
          <template slot-scope="scope" slot="header">
            <div>课下作业</div>
            <div>(已录/已审)</div>
          </template>
        </el-table-column>
        <el-table-column prop="ktreview" width="109" align="center">
          <template slot-scope="scope" slot="header">
            <div>课下测评</div>
            <div>(已录/已审)</div>
          </template>
        </el-table-column>
        <el-table-column prop="qzreview" width="110" align="center">
          <template slot-scope="scope" slot="header">
            <div>期中考试</div>
            <div>(已录/已审)</div>
          </template>
        </el-table-column>
        <el-table-column prop="kzreview" align="center">
          <template slot-scope="scope" slot="header">
            <div>课终考核</div>
            <div>(已录/已审)</div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- <div class="bottom-block">
      <div class="export-button">
        <img src="../../../assets/assessment/icon-export.png" alt="" />
        <download-excel
          class="export-btn"
          :data="tableData"
          :fields="jsonFields"
          type="xls"
          name="填报课程考试计划.xls"
          style="color: #f3b815"
        >
          &ensp;导出Excel
        </download-excel>
      </div>
      <div class="text">授课教员名字后加“*”为课程负责人</div>
    </div> -->
    <!--    导出总评
             //分项
          showExportReportDialogags:false,
          //总评
          showExportReportDialog: false,
          -->
    <el-dialog
      title="导出总评成绩单"
      :visible.sync="showExportReportDialog"
      class="manual-entry-container"
      width="1185px"
    >
      <div>
        <el-row>
          <el-col :span="12">
            <div style="background: rgba(77, 129, 192, 0.1)">成绩范围:</div>
          </el-col>
          <el-col :span="12">
            <el-radio-group v-model="reportTypep">
              <el-radio
                :label="item.label"
                v-for="(item, index) in reportTypepss"
                :key="index"
                class="large"
                >{{ item.value }}
              </el-radio>
            </el-radio-group>
          </el-col>
        </el-row>
      </div>
      <span slot="footer" class="dialog-footer">
        <button class="yellow" @click="savefx">确 定</button>
      </span>
    </el-dialog>
    <el-dialog
      title="导出分项成绩单"
      :visible.sync="showExportReportDialogags"
      class="manual-entry-container"
      width="1185px"
    >
      <div>
        <el-row>
          <el-col :span="12">
            <div style="background: rgba(77, 129, 192, 0.1)">成绩范围:</div>
          </el-col>
          <el-col :span="12">
            <el-radio-group v-model="reportTypep">
              <el-radio
                :label="item.label"
                v-for="(item, index) in reportTypepss"
                :key="index"
                class="large"
                >{{ item.value }}
              </el-radio>
            </el-radio-group>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <div style="background: rgba(77, 129, 192, 0.1)">成绩类型:</div>
          </el-col>
          <el-col :span="12">
            <el-radio-group v-model="reportType">
              <el-radio
                :label="item.label"
                v-for="(item, index) in reportTypes"
                :key="index"
                class="large"
                >{{ item.value }}
              </el-radio>
            </el-radio-group>
          </el-col>
        </el-row>
      </div>
      <span slot="footer" class="dialog-footer">
        <button class="yellow" @click="savefx">确 定</button>
      </span>
    </el-dialog>
    <el-dialog
      title="按模板导入课程成绩"
      :visible.sync="showInportReportDialog"
      class="import-report-container"
      width="983px"
    >
      <div>
        <span>请选择数据文件：</span>
        <input type="text" v-model="filepath" />
        <div>
          <span>浏览</span>
          <input type="file" @change="getFile($event)" />
        </div>
        <div @click="downLoadExcel">下载数据模板文件</div>
      </div>
      <span slot="footer" class="dialog-footer">
        <button class="green" @click="showInportReportDialog = false">
          提交
        </button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  getLists,
  chax,
  saveover,
  savefx,
  tjExcelonObject,
} from "../../../api/courseAchievement/printEntry";
import { getUpload } from "@/api/propositionReview/approval";

export default {
  data() {
    return {
      // jsonFields: {
      //   教员: "teacherName",
      //   系: "df",
      //   教研室: "department",
      //   职称: "rank",
      //   "高/中/初职": "jobGrade",
      //   是否优质课: "goodLesson",
      //   课程名称: "courseName",
      //   课程性质: "teachNature",
      //   承担任务: "task",
      //   "实装/实弹": "actual",
      //   "装备名称/型号": "equipment",
      //   教学对象: "teachObject",
      //   教学班名称: "className",
      //   实际上课人数: "studentNumber",
      //   实际理论讲授课时: "jshour",
      //   实际实践讲授课时: "sjhour",
      //   实际合计课时: "conuthour",
      //   课时折算系数: "acc",
      //   课时量: "workload",
      //   课时标准: "classStandard",
      //   优质课增发课时: "addHours",
      //   优质课增发标准: "addStandard",
      //   备注: "commonts",
      // },
      planid: "",
      planidArr: [],
      termid: "2020春",
      xqList: [
        {
          value: "2021秋",
          label: "2021秋",
        },
        {
          value: "2020夏",
          label: "2020夏",
        },
      ],
      traininglevel: "",
      pyccList: [
        {
          value: "大专",
          label: "大专",
        },
        {
          value: "本科",
          label: "本科",
        },
      ],
      studytype: "",
      xxlxList: [
        {
          value: "选修",
          label: "选修",
        },
        {
          value: "必修",
          label: "必修",
        },
      ],
      tableData: [
        // {
        //   lrcj: "",
        //   dccjd: "",
        //   planid: "12121212",
        //   termid: "2021春",
        //   teachingandresearchsection: "政治教研室",
        //   coursenumber: "061029(博士课)",
        //   coursename: "话语分析专题研究",
        //   grade: "2021",
        //   classes: "2021-(博士课)话语分析专题研究jxb-1",
        //   professionaldivisions: "021英语语言学",
        //   yzjy: "张某某",
        // },
        // {
        //   lrcj: "",
        //   dccjd: "",
        //   termid: "2021夏",
        //   teachingandresearchsection: "政治教研室",
        //   coursenumber: "061029(博士课)",
        //   coursename: "话语分析专题研究",
        //   grade: "2021",
        //   classes: "2021-(博士课)话语分析专题研究jxb-1",
        //   professionaldivisions: "021英语语言学",
        //   yzjy: "张某某",
        // },
      ],
      coursename: "",
      //分项
      showExportReportDialogags: false,
      //总评
      showExportReportDialog: false,
      reportIndex: "",
      showInportReportDialog: false,
      reportType: "课下作业",
      reportTypes: [
        { label: "课下作业", value: "课下作业" },
        { label: "课下测评", value: "课下测评" },
        { label: "期中考试", value: "期中考试" },
        { label: "课终考核", value: "课终考核" },
      ],
      reportTypep: "按教学班导出",
      reportTypepss: [
        { label: "按教学班导出", value: "按教学班导出" },
        { label: "按课程导出", value: "按课程导出" },
      ],
    };
  },
  methods: {
    handleSelectionChange(val) {
      //定义一个临时数组
      for (var i = 0; i < val.length; i++) {
        //循环遍历当前数组
        //判断当前数组下标为i的元素是否已经保存到临时数组
        //如果已保存，则跳过，否则将此元素保存到临时数组中
        if (this.planidArr.indexOf(val[i].planid) == -1) {
          this.planidArr.push(val[i].planid);
        }
      }
      console.log(this.planidArr);
    },
    //分项
    save(index) {
      this.showExportReportDialogags = true;
      this.reportIndex = index;
    },
    savefx() {
      let el = this;
      let fx = this.reportType; //成绩类型:
      if (this.reportTypep == "按教学班导出") {
        let classesid1 = this.tableData[this.reportIndex].classesid;
        // let href =  window.location.origin + `/api/xpaas-course-service/scorequery/outoverFxrating?classid1=${classesid1}&&fx=${fx}`;
        let href =
          window._CONFIG.previewurl +
          `/scorequery/outoverFxrating?classid1=${classesid1}&fx=${fx}`;
        let alink = document.createElement("a");
        el.$message({
          showClose: true,
          message: "下载中，请稍后",
          type: "success",
        });
        alink.style.display = "none";
        alink.download = "按教学班导出.word"; //下载后文件名
        alink.href = href;
        document.body.appendChild(alink);
        alink.click();
        document.body.removeChild(alink); //下载完成移除元素
      } else {
        let planid1 = this.tableData[this.reportIndex].planid;
        let href =
          window._CONFIG.previewurl +
          `/scorequery/outoverFxrating?planid1=${planid1}&fx=${fx}`;
        let alink = document.createElement("a");
        el.$message({
          showClose: true,
          message: "下载中，请稍后",
          type: "success",
        });
        alink.style.display = "none";
        alink.download = "按课程导出.word"; //下载后文件名
        alink.href = href;
        document.body.appendChild(alink);
        alink.click();
        document.body.removeChild(alink); //下载完成移除元素
      }
      this.showExportReportDialogags = false;
      true.showExportReportDialog = false;
    },
    downLoadExcel() {
      let el = this;
      let planid = this.tableData[this.reportIndex].planid;
      let href =
        window._CONFIG.previewurl +
        `/scorequery/downLoadExcel?planid=${planid}`;
      let alink = document.createElement("a");
      el.$message({
        showClose: true,
        message: "下载中，请稍后",
        type: "success",
      });
      alink.style.display = "none";
      alink.download = "按课程导出.word"; //下载后文件名
      alink.href = href;
      document.body.appendChild(alink);
      alink.click();
      document.body.removeChild(alink); //下载完成移除元素
    },
    //总评
    savezong(index) {
      this.showExportReportDialog = true;
      this.reportIndex = index;
    },
    saveover(th) {
      let obj = [th];
      return new Promise(() => {
        saveover(obj).then((res) => {
          this.tableData = res.data.data;
          this.getList();
        });
      });
    },
    lucjClick(index) {
      this.showInportReportDialog = true;
      this.reportIndex = index;
    },
    getFile() {
      let file = event.target.files;
      let planid = this.tableData[this.reportIndex].planid;
      console.log(planid);
      let form = new FormData();
      form.append("file", file[0]);
      form.append("planid", planid);

      let el = this;
      return new Promise(() => {
        tjExcelonObject(form).then((res) => {
          if (res.data.code === 200) {
            el.filepath = file[0].name;

            el.$message({
              showClose: true,
              message: "上传成功",
              type: "success",
            });
          } else {
            el.filepath = "";
            el.$message({
              showClose: true,
              message: "上传失败，请重新上传",
              type: "error",
            });
          }
        });
      });
    },
    toManualEntry(planid) {
      this.$router.push({
        path: "/teacher/courseAchievement/manualEntry",
        query: { planid: planid },
      });
    },
    toMakeupScoreEntry() {
      this.$router.push("/teacher/courseAchievement/entryResults");
    },
    getList: function () {
      let obj = {
        termid: "2020春",
      };
      return new Promise(() => {
        getLists(obj).then((res) => {
          console.log("查看数据");
          this.tableData = res.data.data;
          console.log(res.data.data, "res.data.data");
          // console.log(this.config)
        });
      });
    },
    queryPostList: function () {
      let obj = {
        termid: this.termid,
        traininglevel: this.traininglevel,
        studytype: this.studytype,
        coursename: this.coursename,
      };
      return new Promise(() => {
        chax(obj).then((res) => {
          this.tableData = res.data.data;
        });
      });
    },
  },
  mounted() {
    this.getList();
  },
};
</script>
<style lang="less" scoped>
.manual-entry-container {
  .el-dialog__body {
    > div {
      width: 1014px;
      border: 1px solid rgba(0, 76, 167, 0.8);
      border-radius: 6px;
      margin: 0 auto;

      > div {
        border-bottom: 1px solid rgba(0, 76, 167, 0.39);

        &:last-child {
          border-bottom: none;
        }

        > div {
          display: flex;

          > div {
            height: 96px;
            display: flex;
            align-items: center;
            justify-content: center;

            &:nth-child(1) {
              width: 80%;

              text-align: center;
              font-size: 16px;
              font-weight: bold;
              color: #004ca7;
            }

            &:nth-child(1) {
              height: 200px;
            }
          }
        }
      }
    }
  }

  .el-dialog__footer {
    padding-bottom: 43px;
  }

  .dialog-footer {
    > button {
      width: 95px;
      height: 36px;
      background: #fff6ef;
      border: 1px solid #f3b815;
      border-radius: 6px;
      background: rgba(255, 246, 239, 1);
      font-size: 18px;
      color: #f3b815;
    }
  }
}

.assessment-container {
  .export-report-container {
    .el-dialog__body {
      padding: 64px 0 64px 50px;

      .el-radio {
        margin-right: 79px;
      }
    }

    .el-dialog__footer {
      padding-bottom: 103px;
    }
  }

  .import-report-container {
    .el-dialog__body {
      padding-left: 165px;
      padding-top: 71px;
      padding-bottom: 60px;

      > div {
        > span {
          font-size: 18px;
          font-weight: bold;
          line-height: 20px;
          color: #004ca7;
          vertical-align: middle;
        }

        > input {
          width: 254px;
          height: 25px;
          border: 1px solid #004ca7;
          opacity: 1;
          border-radius: 4px;
          padding-left: 5px;
          margin-right: 8px;
          color: #004ca7;
          vertical-align: middle;
        }

        > div {
          display: inline-block;
          font-size: 18px;
          padding: 1px 10px;
          border-radius: 4px;
          vertical-align: middle;
          cursor: pointer;

          &:nth-child(3) {
            color: rgba(2, 200, 108, 1);
            background: #f1fff8;
            border: 1px solid #02c86c;
            position: relative;
            margin-right: 20px;

            > input {
              width: 822px;
              position: absolute;
              left: -767px;

              cursor: pointer;
            }
          }

          &:nth-child(4) {
            color: rgba(82, 48, 233, 1);
            background: rgba(235, 230, 255, 1);
            border: 1px solid rgba(82, 48, 233, 1);
          }
        }
      }
    }

    .el-dialog__footer {
      padding-bottom: 76px;

      .green {
        padding: 1px 17px;
      }
    }
  }
}

.plan-entry-table-container {
  margin-top: 30px;

  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }

  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }

  .el-checkbox__inner:hover {
    border-color: #004ca7;
  }

  .el-checkbox__inner {
    border: 1px solid #004ca7;
    border-radius: 0;
  }

  .el-checkbox__input.is-checked .el-checkbox__inner,
  .el-checkbox__input.is-indeterminate .el-checkbox__inner {
    background-color: #004ca7;
    border-color: #004ca7;
  }

  .el-checkbox__input.is-checked + .el-checkbox__label {
    color: #004ca7;
  }

  .el-checkbox.is-bordered.is-checked {
    border-color: #004ca7;
  }

  .el-checkbox__input.is-focus .el-checkbox__inner {
    border-color: #004ca7;
  }

  .export-button {
    background: #fff6ef;
    border: 1px solid #f3b815;
    width: auto;
    height: 28px;
    line-height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding: 3px 10px;
    box-sizing: border-box;

    > span {
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #f3b815;
    }

    > img {
      width: 16px;
      height: 16px;
      margin-right: 5px;
    }
  }

  .lucj-import-button {
    .export-button;
    width: 116px;
    margin: 0 auto 12px;
    background: #f1fff8;
    border: 1px solid #02c86c;

    &:last-child {
      margin-bottom: 0px;
    }

    > span {
      color: #02c86c;
    }
  }

  .lucj-expot-button {
    .export-button;
    background: #fff6ef;
    border: 1px solid #f3b815;
    width: 81px;
    margin: 0 auto 12px;

    &:last-child {
      margin-bottom: 0px;
    }

    > span {
      color: #f3b815;
    }
  }
}
</style>

<style lang="less" scoped>
@import "../../../styles/print-entry.less";

.plan-entry-table-container {
  margin-top: 30px;

  .table-data {
    width: 100%;
    border: 0.8px solid #004ca7;
    border-radius: 9px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}
</style>
